UNmiss <- read.table("~/Dropbox/research/RisingPowers/Rising powers/ws5765.csv", header = T, sep = ",")
# create new dataset without missing data 
UN <- na.omit(UNmiss)
UNnames <- UN[, 1]
legData <- matrix(UN[, 2], length(UN[, 2]), 1)
colnames(legData) <- "party"
UN <- UN[, -c(1, 2)]
rc <- rollcall(UN, yea = 1, nay = c(2,3), missing = 8, notInLegis = 9, legis.names = UNnames, legis.data = legData, desc = "UN Votes", source = "www.voteview.com")
result <- wnominate(rc, polarity = c(1, 1))

summary(result)
plot(result)
legisdata <- result$legislators

#Export legisdata to STATA
# export data frame to Stata binary format 
library(foreign)
write.csv(legisdata, "~/Dropbox/research/RisingPowers/BP_replication/ip5765.csv")


#Modify rollcall by fix(rollcall)


# recode 99 to missing for variable v1
# select rows where v1 is 99 and recode column v1 
mydata[mydata$v1==99,"v1"] <- NA

#Not this just want to fix Russia and Germany
#UNmiss[is.na(UNmiss)] <- 9